	
	// this sets the background color of the master UIView (when there are no windows/tab groups on it)

Titanium.UI.setBackgroundColor('#000');

Titanium.UI.orientation = Titanium.UI.PORTRAIT;

var quotes=new Array();

quotes[0]=new Array();
quotes[0][0]="Oscar Wilde"; // author
quotes[0][1]="A dreamer is one who can only find his way by moonlight, and his punishment is that he sees the dawn before the rest of the world. ";
quotes[0][2]="Oscar Wilde"; // suggestion 1
quotes[0][3]="James Baldwin"; // suggestion 2
quotes[0][4]="Hector Berlioz";  // suggestion 3

quotes[0]=new Array();
quotes[0][0]="Oscar Wilde"; // author
quotes[0][1]="A gentleman is one who never hurts anyone. ";
quotes[0][2]="Oscar Wilde"; // suggestion 1
quotes[0][3]="James Baldwin"; // suggestion 2
quotes[0][4]="Hector Berlioz";  // suggestion 3

fisherYates(quotes); // shuffle

Titanium.App.Properties.setInt("counter", 0 );

var author = quotes[0][0];
var quote = quotes[0][1];
var suggestion1 = quotes[0][2];
var suggestion2 = quotes[0][3];
var suggestion3 = quotes[0][3];


// create tab group
var tabGroup = Titanium.UI.createTabGroup();



//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    title:'Today\'s Quote',
    backgroundColor:'#eaeaea'
});
var tab1 = Titanium.UI.createTab({  
//    icon:'KS_nav_question.png',
    title:'Famous Quote Quiz',
    window:win1
});



var labelQuote = Titanium.UI.createLabel({
	color:'#666666',
	text: quote,
	font:{fontSize:15,fontFamily:'Helvetica Neue'},
	textAlign:'left',
	left: 10,
	width:'auto'
});
win1.add(labelQuote);

var labelAuthor = Titanium.UI.createLabel({
	color:'#062a04',
    backgroundColor:'#e3fde2',
    borderColor: '#e3fde2',
	borderRadius: 6,
    borderWidth: 5,
	text: author,
	textAlign:'center',
	width:'auto',
	top: 20,
	height: 40,
    visible:false
});
win1.add(labelAuthor);



var suggestionLabel = Titanium.UI.createLabel({
	color:'#062a04',
    backgroundColor:'#faeda9',
    borderColor: '#faeda9',
	borderRadius: 6,
    borderWidth: 5,
	text: suggestion1, // or suggestion 2, or suggestion 3
	textAlign:'center',
	width:'auto',
	top: 25,
	height: 20,
    visible:false
});
win1.add(suggestionLabel);


var suggestionYes = Titanium.UI.createButton({ 
	title: 'Yes' ,
    backgroundColor:'#6da134',
	color:'#ffffff',
	borderRadius: 6
}); 

win1.add(suggestionYes);

var suggestionNo = Titanium.UI.createButton({ 
	title: 'No' ,
    backgroundColor:'#f90544',
	color:'#ffffff',
	borderRadius: 6
}); 


win1.add(suggestionNo);




suggestionLabel.addEventListener('click', showAnswer);

suggestionYes.addEventListener('click', checkAnswerForYes);

suggestionNo.addEventListener('click', checkAnswerForNo);







// JS fuinction library 



function fisherYates ( myArray ) {// shuffle
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}


function checkAnswerForYes(e)
{
	if ( suggestionLabel.text == authorLabel)
	{
		alert('Correct!');
	} else {
		alert('Wrong!');
	}

	showAnswer(e);

}


function checkAnswerForNo(e)
{

	if ( suggestionLabel.text != authorLabel)
	{
		alert('Correct!');
	} else {
		alert('Wrong!');
	}


	showAnswer(e);

}


function showAnswer(e)
{
  authorLabel.animate({
   opacity:1.0,
   duration:500
  });
  
  
  suggestionLabel.animate({
   opacity:0.0,
   duration:500
  }); 
  suggestionYes.animate({
   opacity:0.0,
   duration:500
  }); 
  suggestionNo.animate({
   opacity:0.0,
   duration:500
  }); 

  fisherYates(quotes);	

}
	